package safeCommitter.core.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

import safeCommitter.core.template.ISCTemplate;
import safeCommitter.core.template.SCTemplate;

/**
 * 
 * 
 * Entry point for the SafeCommiter action.The
 * {@link #selectionChanged(IAction, ISelection)} method will be called first,
 * when the user right click's a registered component (like a class or package)
 * while the {@link #run(IAction)} method will be triggered on the moment the
 * user clicks the correspondent safeCommit menu item.
 * 
 * @author Luiz Henrique Rolim
 */
public class SafeCommit implements IObjectActionDelegate {

	private final ISCTemplate safeCommiter = new SCTemplate();

	/**
	 * Constructor for Action1.
	 */
	public SafeCommit() {
		super();
	}

	/**
	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
	 */
	public void setActivePart(final IAction action,
			final IWorkbenchPart targetPart) {
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(final IAction action) {
		safeCommiter.executeTests(action);
	}

	/**
	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
	 */
	public void selectionChanged(final IAction action,
			final ISelection selection) {
		safeCommiter.setSelection(selection, action);
	}

}
